home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Other / power / ctime.c next >
Encoding:
C/C++ Source or Header  |  1991-09-14  |  1.2 KB  |  77 lines

  1. /*
  2.  * ctime time_t ... - print the ascii time of time_t(s)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <time.h>
  8. #include <sys/types.h>
  9. #include <sys/timeb.h>
  10.  
  11. /* privates */
  12. static struct timeb ftnow;
  13. static int gmt = 0;
  14.  
  15. char *progname;
  16.  
  17. /* imports */
  18. extern long atol();
  19. extern char *malloc(), *ctime(), *asctime();
  20. extern struct tm *gmtime();
  21. extern time_t time();
  22.  
  23. /* Forwards. */
  24. extern void process();
  25. extern int optind;
  26. extern char *optarg;
  27.  
  28. /*
  29.  - main - parse arguments and handle options
  30.  */
  31. main(argc, argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.     register int c, errflg = 0;
  36.  
  37.     progname = argv[0];
  38.     ftime(&ftnow);
  39.  
  40.     while ((c = getopt(argc, argv, "u")) != EOF)
  41.         switch (c) {
  42.         case 'u':
  43.             ++gmt;
  44.             break;
  45.         case '?':
  46.         default:
  47.             errflg++;
  48.             break;
  49.         }
  50.     if (errflg || optind == argc) {
  51.         (void) fprintf(stderr, "Usage: %s [-u] int_time ...\n",
  52.                    progname);
  53.         exit(2);
  54.     }
  55.  
  56.     for (; optind < argc; optind++)
  57.         process(argv[optind]);
  58.     exit(0);
  59. }
  60.  
  61. /*
  62.  * process - print time_t of tm
  63.  */
  64. void
  65. process(tms)
  66. char *tms;
  67. {
  68.     time_t tm = atol(tms);
  69.  
  70.     if (gmt) {
  71.         register struct tm *prstime = gmtime(&tm);
  72.  
  73.         (void) fputs(asctime(prstime), stdout);
  74.     } else
  75.         (void) fputs(ctime(&tm), stdout);
  76. }
  77.